package interview.volatiled;
/****
 *  验证volatile保证可见性
 *
 * **/

class MyData{

    public        int  number=0;

    public  void update(){
        this.number=90;
    }
}

public class VolatileDemo1 {
    public static void main(String[] args) {
        MyData myData = new MyData();
        new Thread(()->{
            System.out.println(Thread.currentThread().getName());
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            myData.update();
            System.out.println("数值number已经被更新为："+myData.number);
        },"AAA").start();
        int i=0;

        while (myData.number==0){
          /*  try {
                Thread.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }*/
        }

        System.out.println("************end**************"+myData.number);
    }
}

//钱多事少离家近
//位高权重责任轻